import java.util.ArrayList;
import java.util.Scanner;

public class AppMain {
    static ArrayList<String> name = new ArrayList<>();//点餐人
    static String[] dishname = {"宫爆鸡丁","西红柿炒鸡蛋","爆炒牛杂","紫菜蛋花汤","小鸡炖蘑菇"}; //菜名
    static ArrayList<String> selected  = new ArrayList<>();//订单内容
    static ArrayList<String> address = new ArrayList<>();//地址
    static int[] unitPrice = {50,15,55,20,45};//单价
    static int[] likeCount = {0,0,0,0,0};//点赞数
    static ArrayList<Integer> time = new ArrayList<>();//送餐时间
    static ArrayList<Integer> state = new ArrayList<>();//状态
    static ArrayList<Integer> totalPrice = new ArrayList<>();//总价
    static int quantity;//菜的数量

    public static void main(String[] args) {
        main();
    }

    public static void main() {
        System.out.println("欢迎使用“漂亮团外卖\n" +
                "**********************\n" +
                "1、我要订餐\n" +
                "2、我的订单\n"+
                "3、签收订单\n"+
                "4、删除订单\n"+
                "5、我要点赞\n"+
                "6、退出系统\n"+
                "**********************\n"+
                "请选择：");

        Scanner number = new Scanner(System.in);
        int num = number.nextInt();
        switch (num){
            case 1:
                orderingMeals();
                break;
            case 2:
                orderForm();
                break;
            case 3:
                signFor();
                break;
            case 4:
                delete();
                break;
            case 5:
                like();
                break;
            default:
                quit();
                break;
        }

    }

//    我要订餐
    public static void orderingMeals(){
        quantity=0;
        int a = 0,sum;
        int timeing;
        Scanner sc = new Scanner(System.in);
        System.out.println("菜单\n" +
                "***********************************\n" +
                "\t菜名"+"\t\t\t单价"+"\t\t\t点赞数");
        for (int i = 1; i <= dishname.length; i++) {
            System.out.println(String.format("%-11s\t%-10d\t%d", i+"、"+dishname[i - 1], unitPrice[i - 1], likeCount[i - 1]));
        }
        System.out.println("***********************************");
        while(a>=0){
            System.out.println("订餐人姓名：");
            name.add(sc.next());
            System.out.println("请选择所需菜名前的序号：");
            int number=sc.nextInt();
            while (true){
                if(number>dishname.length){
                    System.out.println("输入错误，重新输入：");
                    number=sc.nextInt();
                }
                else {
                    break;
                }
            }

            selected.add(dishname[number-1]);
            System.out.println("当前菜品份数");
            quantity=sc.nextInt();
            selected.set(selected.size()-1, selected.get(selected.size()-1)+"*" + quantity);
            System.out.println("所在地址：");
            address.add(sc.next());
            System.out.println("送达时间：");
            while(true){
                timeing = sc.nextInt();
                if(timeing>=10 && timeing<=20){
                    time.add(timeing);
                    break;
                }
                else {
                    System.out.println("送达时间错误,只允许在10-20点之间，请重新输入：");
                }
            }
            state.add(0);//订单默认未送达
            sum =unitPrice[number-1]* quantity;//菜总价
            if(sum<=50){
                sum+=6;//送餐费
                totalPrice.add(sum);
            }
            else {
                totalPrice.add(sum);
            }

            System.out.println("订餐成功，请输入0查看订单信息，输入1继续订餐");
            int num = sc.nextInt();
            if(num==0){
                orderForm();
                break;
            }
            else {
                a++;
            }

        }
    }

//展示订单
    public static void show(){

        System.out.println("订单信息表\n" +
                "****************************************************************************************************\n" +
                "\t订单号"+"\t\t\t钉餐人"+"\t\t\t菜品*数量\t\t\t送餐时间\t\t送餐地址\t\t\t状态\t\t总金额");
        if (name.size()==0){
            System.out.println("您还没有进行点餐。");
        }
        for (int i = 0; i < name.size(); i++) {
            System.out.print(String.format("%6d\t\t\t\t%-12s\t%-10s\t%d",i+1,name.get(i),selected.get(i),time.get(i),state.get(i)));
            System.out.print(String.format("\t\t\t%-12s",address.get(i)));
            if(state.get(i)==0){
                System.out.print("\t\t已预定");
            }
            else {
                System.out.print("\t\t"+"已签收");
            }
            System.out.println("\t"+totalPrice.get(i));

        }
        System.out.println("****************************************************************************************************\n");
    }

//    我的订单
    public static void orderForm(){
        Scanner sc = new Scanner(System.in);
        show();
        System.out.println("返回到主菜单输入0，退出系统请输入6：");
        if (sc.nextInt()==0){
            main();
        }
        else {
            quit();
        }
    }

//    签收订单
    public static void signFor(){
        int num;
        Scanner sc = new Scanner(System.in);
        show();
        while (true) {
            System.out.println("请选择要签收的订单编号：");
            num=sc.nextInt();
            if(state.get(num-1)==1){
                System.out.println("该订单已签收，请重新输入：");

            }
            else {
                state.set(num-1,1);
                break;
            }
        }

        System.out.println("签收成功");
        System.out.println("继续签收输入1，返回主菜单输入0：");
        if(sc.nextInt()==0){
            main();
        }
        else {
            signFor();
        }
    }

//    删除订单
    public static void delete(){
        int num;
        Scanner sc = new Scanner(System.in);
        show();
        System.out.println("请选择要删除的订单编号：");
        num=sc.nextInt();
        name.remove(num-1);
        selected.remove(num-1);
        time.remove(num-1);
        state.remove(num-1);
        time.remove(num-1);
        address.remove(num-1);
        totalPrice.remove(num-1);
        System.out.println("删除成功");
        System.out.println("继续删除输入1，返回主菜单输入0：");
        if(sc.nextInt()==0){
            main();
        }
        else {
            delete();
        }
    }


//    我要点赞
    public static void like(){
        int num;
        show();
        Scanner sc = new Scanner(System.in);
        System.out.println("请选择要点赞的订单编号：");
        num = sc.nextInt();
        for (int i = 0; i < dishname.length; i++) {
            if(selected.get(num-1).indexOf(dishname[i])!=-1){
                likeCount[i]++;
                break;
            }
        }
        System.out.println("点赞成功");
        System.out.println("继续点赞输入1，返回主菜单输入0：");
        if(sc.nextInt()==0){
            main();
        }
        else {
            like();
        }
    }

//    退出系统
    public static int quit(){
        System.out.println("退出系统成功");
        return 0;
    }

}